Use case: Write and read operations

Sequence diagram

Write and read operations

  @startuml

  participant App as "User application"
  participant HAL as "HAL Driver"

  == Prerequisite: initialization and configuration ==

  == Process ==
  App -> HAL : HAL_SDRAM_Write_xx()
  note right:  Write HAL operation

  App <-- HAL : hal_status : HAL_OK or HAL_ERROR
  note right:  Return status

  App -> HAL : HAL_SDRAM_Read_xx()
  note right:  Read HAL operation

  App <-- HAL : hal_status : HAL_OK or HAL_ERROR
  note right:  Return status

  @enduml

Code snippet

HAL1

HAL2

/* - */



/* Write data operation */
HAL_SDRAM_Write_8b(&hsdram,
                    (uint32_t *)(device_address),
                    data_to_write,
                    BufferSize

                   );
/* Read data operation */
HAL_SDRAM_Read_8b(&hsdram,
                   (uint32_t *)(device_address),
                   data_read,
                   BufferSize
                  );
uint32_t size;
uint8_t *psdramaddress = (uint8_t *)device_address;
uint8_t *psrcbuff = data_to_write;
uint8_t *pdestbuff = data_read;
/* Write data to memory */
for (size = BufferSize; size != 0U; size--)
{
   *psdramaddress = *psrcbuff;
   psrcbuff++;
   psdramaddress++;
}
/* Read data from memory */
for (size = BufferSize; size != 0U; size--)
{
   *pdestbuff = *psdramaddress;
   pdestbuff++;
   psdramaddress++;
}

Key changes

  1. HAL2 removes SDRAM read/write APIs because SDRAM is memory mapped.

  2. Data accesses are performed directly through memory read/write operations.